<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="false">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row :gutter="48">
          <a-col :span="24">
            <a-form-model-item label="进度节点名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="nodeName">
              <a-input :disabled=formDisabled v-model="model.nodeName" placeholder="请输入进度节点名称"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="进度节点说明" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="nodeDesc">
              <a-textarea :disabled="formDisabled" :max-length="500" v-model="model.nodeDesc" rows="4" placeholder="请输入备注"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="关联任务进度节点" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taskNodeId">
              <select-progress-contract-detail-input ref="detail_input" v-model="model.taskNodeId" :multi="true" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

import { httpAction, getAction } from '@/api/manage'
import { validateDuplicateValue } from '@/utils/util'
import SelectProgressContractDetailInput from '@/views/scy/components/SelectProgressContractDetailInput'

export default {
  name: 'ErpProgressContractDetailForm',
  components: {
    SelectProgressContractDetailInput
  },
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  data() {
    return {
      model: {
      },
      labelCol: {
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 24 },
      },
      confirmLoading: false,
      validatorRules: {
        nodeName: [
          { required: true, message: '请输入进度节点名称!' },
          // { validator: (rule, value, callback) => validateBlankValue('erp_employee_file', 'department_id', value, this.model.id, callback) },
        ],
        taskNodeId: [
          { required: true, message: '请选择关联任务进度节点!' },
          // { validator: (rule, value, callback) => validateBlankValue('erp_seal_certificate_file_manage', 'seal_type', value, this.model.id, callback) },
        ],
      },
      url: {
        add: "/api/erp/progress/erpProgressContract/add",
        edit: "/api/erp/progress/erpProgressContract/edit",
        queryById: "/api/erp/progress/erpProgressContract/queryById"
      },
      oldmode: ''
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    },
  },
  created() {
    //备份model原始值
    // this.modelDefault = JSON.parse(JSON.stringify(this.model));
  },
  methods: {
    getTemplateList(data) {
      this.dataSource = data;
    },
    add(mode) {
      console.log("huoqu===============", mode);
      // this.oldmode = mode.id
      this.$refs.detail_input.getOld(mode.id)
      this.model = {}
      // this.edit(this.modelDefault);
    },
    edit(id,record) {
      // this.$refs.form.resetFields();
      this.model = {}
      this.$refs.detail_input.getOld(id)
      this.model = Object.assign({}, record);
      this.$refs.detail_input.initObj(record.taskNodeId)
      this.visible = true;
    },
    submitForm() {
      const that = this;
      console.log("珍惜呵护私======", this.model);
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          if (!this.model.id) {
            this.model.id = parseInt(Math.random() * 1000000000000);
          }
          this.$refs.detail_input.selectedObj = []
          this.$refs.detail_input.ids = []
          that.$emit('ok', this.model);
        }
      })
    },
  }
}
</script>
